<?php
/**
 * 用户发送短信
 * User: csyr
 * Date: 16/7/10
 * Time: 下午8:53
 */

namespace Common\Library;


use Think\Cache\Driver\Redis;
use Think\Log;
include('/home/wwwroot/api.huoyanzichan.com/MaiBei/Common/Library/AliSdk/TopSdk.php');

class SendSMS {
    /*云杏短信通道配置*/
    const YUNXIN_PREFIX_KEY = 'SendSMS::';
    const YUNXIN_URL = 'http://api.sms.cn/sms/?';
    const YUNXIN_PWD = '2464a20a838a94e82c06ecfcb5914a0f';
    const YUNXIN_UID = 'huoyanzichan';
    /*红莲短信通道配置*/
    const HONGLIAN_PREFIX_KEY = '';
    const HONGLIAN_URL = 'http://114.255.71.158:8061?';
    //const PWD = 'Hysdyx456';
    const HONGLIAN_PWD = 'Hysdyz123';
    //const UID = 'hysdyz';
    const HONGLIAN_UID = 'hysdyz';
    /*云峰短信通道配置信息|xml*/
    const yunfeng_app_key='9ylyb2t09osoaczcbxz6a1u8iyxam4nz';
    const  yunfeng_nonce_str='zhaoqianh';
    const  yunfeng_appsecret='93ff80f9c9bd3b222398896dc07f96aa7665';
    /*********云峰短信通道|json********/
    const yunfeng_json_url='http://api.cloudfeng.com/restful/v1/sms/send.json?';
    /*云峰短信通道余额查询*/
    const yunfeng_left_url='http://api.cloudfeng.com/api/v1/getSmsCount';
    const TYPE_VERIFY_CODE = 'verify_code';
    const VERIFY_CODE_TIMEOUT = 600; //短信验证码10分钟有效期
    //http://api.sms.cn/sms/?ac=send&uid=maibei9&pwd=781082d485ecf7c78f32e2abe9476bd2&template=387042&mobile=填写要发送的手机号&content={"name":"value","amount":"value","day":"value"}
    /*创世华信短信配置*/
    const HUAXIN_USER_NAME = 'jksc1060';
    const HUAXIN_KEY = 'a1234566';
    const HUAXIN_URL = 'http://sh2.ipyy.com/smsJson.aspx';

    
    public static function writeutf8($source)
    {
        try {
            //return (iconv('UTF8','GBK//IGNORE',$source));
            return iconv('UTF-8', 'GBK//IGNORE', $source);
        } catch (Exception $e) {
            return $source;
        }
    }
    
    public static function get_sendSMS($url)
    {
        Log::sms_write('+++++++++++++++++++++++++++++++++++++++++++++++短信接口开始请求信息url：'.$url.'++++++++++++++++++++++++++++++');

        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE);
        $output = curl_exec($ch);
        curl_close($ch);
        Log::sms_write('+++++++++++++++++++++++++++++++++++++++++++++++短信接口返回信息：'.json_encode($output).'++++++++++++++++++++++++++++++');
        return $output;

    }
    
    public static function testsend($mobile, $content){
        //         $URI = "http://114.255.71.158:8061?username=hysdyz&password=Hysdyz123&phone=18162430121&message=".urlencode(writeutf8(
        //             "您好.test"))."&epid=122450&linkid=&subcode=";
    
        $data = [
        'username'=>self::HONGLIAN_UID,
        'password'=>self::HONGLIAN_PWD,
        'phone'=>$mobile,
        'message'=>self::writeutf8($content),
         'epid'=>122450,
        //'epid'=>530,
        ];
        Log::write("&&&&&&&&&&&&&&&&&&&&&&&&&&&验证码发送内容&&&&&&&&&&&&&&&&&&&&&&&&&&&：".json_encode($data), Log::DEBUG);

        $query = self::HONGLIAN_URL.http_build_query($data);
        Log::write("########################testsend的query是：$query#########################################".json_encode($query), Log::DEBUG);
        Log::cron_write("########################testsend的query是：$query#########################################".json_encode($query));

        $retJson = self::get_sendSMS($query);
        $ret = json_decode($retJson, true);
        Log::write("#########################返回结果是：$ret###################################################".json_encode($ret), Log::DEBUG);
        Log::cron_write("#########################返回结果是：".$retJson."###################################################");

        if (isset($ret) && 0 == $ret) {
            return true;
        }else {
            return false;
        }
    }
    /***************测试云峰|查看剩余短信数目*************/
    public static  function yunfeng_amount(){
        //拼接sign 规则app_key=XXX&nonce_str=xxx&time_stamp=20160707100827&app_secret=xxx
        $time=date('YmdHis',time());
        $sign=md5("app_key=".self::yunfeng_app_key."&nonce_str=".self::yunfeng_nonce_str."&time_stamp=".$time."&app_secret=".self::yunfeng_appsecret."");
        $input_xml = '<?xml version="1.0" encoding="UTF-8"?>
							<xml>
								<head>
									<app_key>'.self::yunfeng_app_key.'</app_key>
									<time_stamp>'.$time.'</time_stamp>
									<nonce_str>'.self::yunfeng_nonce_str.'</nonce_str>
									<sign>'.$sign.'</sign>
								</head>
							</xml>';
        //$url = "http://api.cloudfeng.com/api/v1/getSmsCount";
        $url = self::yunfeng_left_url;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$input_xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        $data = curl_exec($ch);
        curl_close($ch);
        var_dump($data);
        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);
        print_r('<pre>');
        print_r($array_data);
        print_r('</pre>');

    }
    /***************测试云峰|查看剩余短信数目*************/

    /**********************云峰json|发送短信********************/
    public static function yunfeng_send_json2($mobile, $content){
        Log::sms_write("【@@@@@@@@@@@@@@@@@@@@@@@@@yunfeng_send_json短信验证码发送内容：".$content.'@@@@@@@@@@@@@@@@@@】');

        //$url='http://api.cloudfeng.com/restful/v1/sms/send.json?';
        $time=date('YmdHis',time());
        $batch_num='cloudfeng1222011';
        //$content='【找钱花】尊敬的用户，本次验证码为123456，请勿泄露';
        $phones=$mobile;
        $sign=md5('app_key='.self::yunfeng_app_key.'&batch_num='.$batch_num.'&content='.$content.'&nonce_str='.self::yunfeng_nonce_str.'&phones='.$phones.'&time_stamp='.$time.'&app_secret='.self::yunfeng_appsecret);
        $data = [
            'app_key'=>self::yunfeng_app_key,
            'batch_num'=>$batch_num,
            'content'=>$content,
            'nonce_str'=>self::yunfeng_nonce_str,
            'phones'=>$phones,
            'time_stamp'=>$time,
            'app_secret'=>self::yunfeng_appsecret,
            'sign'=>$sign,
        ];
        // print_r($data);
        Log::sms_write("【@@@@@@@@@@@@@@@@@@@@@@@@@yunfeng_send_json短信验证码发送内容：".json_encode($data).'@@@@@@@@@@@@@@@@@@】');
        $redis = new Redis();
        $key = '控制用户发送短信次数'.$mobile;
        $num = $redis->get($key);
        if ($num<20){
            Log::sms_write('====+++++++++++============用户短信次数'.$num);
            $query = self::yunfeng_json_url.http_build_query($data);
            Log::sms_write("【@@@@@@@@@@@@@@@@@@云峰url：$query@@@@@@@@@@@@@@@@@@】");
            $retJson = self::get_sendSMS($query);
//                string(38) "{"error_code":"000000","error_msg":""}"
            Log::sms_write("【@@@@@@@@@@@@@@@@@@云峰短信返回结果是：$retJson&@@@@@@@@@@@@@@@@@@】");
            $ret = json_decode($retJson, true);
//                $ret = ['error_code'=>'000000',["error_msg"]=>'SUCCESS'];
        } else {
            Log::sms_write('====+++++++++++============用户短信发送失败，原因++++大于每日短信次数');
            BusinessException::throwException('发送失败');
        }


        /*
         * array(2) {
                      ["error_code"]=>
                      string(6) "000000"
                      ["error_msg"]=>
                      string(0) ""
                    }
        */
        //var_dump($ret);
        if($ret['error_code']=='000000'){
            $key = '控制用户发送短信次数'.$mobile;
            if ($redis->get($key)){
                $redis->set($key,($redis->get($key)+1),21600);
                $a = $redis->get($key);
                Log::sms_write('====+++++++++++============用户短信次数'.$a);
            } else {
                $redis->set($key,1,21600);
                Log::sms_write('====+++++++++++============用户短信次数  1');
            }
            return true;
        }else{
            return false;
        }
    }
    /**********************云峰json********************/
    /***************云峰|短信通道|xml*************/
    public static  function yunfeng_send(){
        //拼接sign 规则 md5“app_key=xx&batch_num=cloudfeng100001&content=xx&dest_id=15267797477&dest_id=13968880707&mission_num=100001&mission_num=100002&nonce_str=cloudfeng&sms_type=verify_code&time_stamp=20160823143033&app_secret=9c789268c8bc21d5d633651bc41ffc995908”
        $time=date('YmdHis',time());
        $sign=md5("app_key=".self::yunfeng_app_key."&batch_num=".self::yunfeng_nonce_str."122201&content=【找钱花】找钱华：测试云峰短信接口&dest_id=13269706193&mission_num=s1562628sss&nonce_str=".self::yunfeng_nonce_str."&sms_type=verify_code&time_stamp=".$time."&app_secret=".self::yunfeng_appsecret."");
        $input_xml = '<?xml version="1.0" encoding="UTF-8"?>
<xml>
	<head>
		<app_key>'.self::yunfeng_app_key.'</app_key>
		<time_stamp>'.$time.'</time_stamp>
		<nonce_str>'.self::yunfeng_nonce_str.'</nonce_str>
		<sign>'.$sign.'</sign>
	</head>
	<body>
		<dests>
			<dest>
				<mission_num>s1562628sss</mission_num>
				<dest_id>13269706193</dest_id>
			</dest>
		</dests>
		<batch_num>'.self::yunfeng_nonce_str.'122201</batch_num>
		<sms_type>verify_code</sms_type>
		<content>【找钱花】找钱华：测试云峰短信接口</content>
	</body>
</xml>
';     echo  $input_xml;
        //$url = "http://api.cloudfeng.com/api/v1/getSmsCount";
        $url = "http://api.cloudfeng.com/api/v1/manySend";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$input_xml);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
        $data = curl_exec($ch);
        curl_close($ch);
        echo  '结果';
        var_dump($data);
        $array_data = json_decode(json_encode(simplexml_load_string($data)), true);
        print_r('<pre>');
        print_r($array_data);
        print_r('</pre>');

    }
    /***************云峰|短信通道|xml*************/
    /********************云峰短信通道|回掉函数*****************************/
    public static function yunfeng_notify(){
        $xml=file_get_contents("php://input");
        Log::write("【******************云峰短信回掉|接口返回数据：".$xml."**********】",Log::DEBUG);
        //转换成array
        $array_data = json_decode(json_encode(simplexml_load_string($xml)), true);
        Log::write("【******************云峰短信回掉|接口返回数据|转成数组|json：".json_encode(simplexml_load_string($xml))."**********】",Log::DEBUG);
        Log::write("【******************云峰短信回掉|head：".json_encode($array_data['head'])."**********】",Log::DEBUG);
        Log::write("【******************云峰短信回掉|head：".json_encode($array_data['body'])."**********】",Log::DEBUG);
        return $array_data;
    }
    /********************云峰短信通道|回掉函数*****************************/
    public static function send($mobile, $content, $template='') {
        $data = [
            'ac'=>'send',
            'format'=>'json',
            'mobile'=>$mobile,
            'uid'=>self::YUNXIN_UID,
            'pwd'=>self::YUNXIN_PWD,
            'content'=>$content,
            'template'=>$template
        ];
        Log::write(json_encode($data), Log::INFO);
        $query = self::YUNXIN_URL.http_build_query($data);
        $retJson = file_get_contents($query);
        Log::write("SMS Ret:".$retJson, Log::INFO);
        $ret = json_decode($retJson, true);
        if (isset($ret['stat']) && 100 == $ret['stat']) {
            return true;
        }
        return false;
    }

    public static function verifyCode($mobile, $type)
    {

        $redis = new Redis();
        Log::write('*********************************************SendSms/verifyCode==================================================redis=:'.json_encode($redis), Log::DEBUG);
        //Log::write('*********************************************SendSms/verifyCode==================================================redis=:'.json_encode($redis), Log::DEBUG);

        $cacheKey = self::HONGLIAN_PREFIX_KEY . self::TYPE_VERIFY_CODE . ':' . $mobile . ':' . $type;
        $verifyCode = $redis->get($cacheKey);
        Log::sms_write('*********************************************SendSms/verifyCode|redis|$cacheKey:'.$cacheKey.'|==================================================redis=:'.json_encode($verifyCode));

        if ($verifyCode) {
            Log::write("============================$verifyCode==================================================verifyCode=:".json_encode($verifyCode), Log::DEBUG);
            $setRedis = false;
        } else {
            $verifyCode = mt_rand(100000, 999999);
            $setRedis = true;
        }

        //$data = array('verifyCode'=>$verifyCode);
        //$ret = self::alisend($mobile, 'register', $data);
        //如果是测试用户，则直接过
        $isTestUser = M('TestWhitelist')->where(['mobile'=>$mobile])->find();
        if ($isTestUser) {
            $verifyCode = 888888;
            $ret = true;
            /*云峰开始*/
            /*$content = "【找钱花】尊敬的用户，找钱花本次验证码为".$verifyCode."，请勿泄露";
            Log::write("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 生成的验证码是：$verifyCode@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :", Log::DEBUG);
            $ret = self::yunfeng_send_json($mobile,$content);
            Log::write("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ $ret@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ret=:".json_encode($ret), Log::DEBUG);
            */
            /*云峰结束*/
        }else{
            /*云杏|红莲短信通道-开始*/
            //$content = "您好，你的手机验证码是：".$verifyCode.", 请妥善保管，勿泄露。【找钱花】";
            //$content = "验证码：$verifyCode，请及时完成验证。";
            //Log::write("&&&&&&&&&&&&&&&&&&& $verifyCode&&&&&&&&&&&&&&&&&&&&& :", Log::DEBUG);
            //$ret = self::testsend($mobile,$content);
            /*云峰短信通道开始--打开以下注释即可（同时注释掉上面的代码）*/
            $content = "【找钱花】尊敬的用户，找钱花本次验证码为".$verifyCode."，请勿泄露";
           Log::sms_write("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 生成的验证码是：$verifyCode@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :");
           $ret = self::yunfeng_send_json($mobile,$content);
           Log::sms_write("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 云峰短信返回结果：$ret@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ret=:".json_encode($ret));

            /*云峰短信通道|结束*/
            Log::sms_write("============================ $ret==================================================ret=:".json_encode($ret));

        }

        if ($ret && $setRedis) {
            if (false === $redis->set($cacheKey, $verifyCode, self::VERIFY_CODE_TIMEOUT)) {
                Log::sms_write("============================ 验证码下发成功, 但记录验证码失败==================================================");

                Log::sms_write('验证码下发成功, 但记录验证码失败。mobile:' . $mobile . ' verify code:' . $verifyCode);
            }
            Log::sms_write("============================ 验证码下发成功, redis的key：".$cacheKey."|验证码：".$cacheKey."==================================================");

        }
        Log::write("============================最后返回结果ret*********************************************=================================================最后返回结果是：".json_encode($ret), Log::DEBUG);
        Log::sms_write("============================最后返回结果ret*********************************************=================================================最后返回结果是：".json_encode($ret));

        return $ret;
    }

    public static function getVerifyCode($mobile, $type) {
        $redis = new Redis();
        $cacheKey = self::HONGLIAN_PREFIX_KEY . self::TYPE_VERIFY_CODE . ':' . $mobile . ':' . $type;

        return $redis->get($cacheKey);
    }

    public static function rmVerifyCode($mobile, $type) {
        $redis = new Redis();
        $cacheKey = self::HONGLIAN_PREFIX_KEY . self::TYPE_VERIFY_CODE . ':' . $mobile . ':' . $type;

        return $redis->delete($cacheKey);
    }

    public static function reviewedUnPass($mobile)
    {
        $content = '尊敬的找钱花用户，您的消费授信审核未通过，请与工作人员联系。【找钱花】';
        //$ret = self::send($mobile, $content);
        $data = array();
        $ret = self::alisend($mobile, 'reviewedUnPass', $data);
        return $ret;
    }

    public static function reviewedPass($mobile)
    {
        $content = '尊敬的找钱花用户，您的消费授信已审核通过。【找钱花】';
        //$ret = self::send($mobile, $content);
        $data = array();
        $ret = self::alisend($mobile, 'reviewedPass', $data);
        return $ret;
    }

    public static function orderRepay($mobile, $name)
    {
        $content = '尊敬的用户，您已成功使用找钱花在“{'.$mobile.'}”付款“{'.$name.
            '}”元请每月10号前准时还款，以免逾期影响您的信用，谢谢【找钱花】';
        //$ret = self::send($mobile, $content);
        $data = array('phone'=>$mobile,'name'=>$name);
        $ret = self::alisend($mobile, 'orderRepay', $data);
        return $ret;
    }

    public static function waitReviewed($mobile)
    {
        $content = '尊敬的找钱花用户，您的消费授信正在审核中，请耐心等待。【找钱花】';
        //$ret = self::send($mobile, $content);
        $data = array();
        $ret = self::alisend($mobile, 'waitReviewed', $data);
        return $ret;
    }

    public static function smsReminder($mobile, $name, $amount, $payday, $phone,$days,$overdue_amount,$day)
    {
        //$content = '亲爱的'.$name.'，您本月账单已出，应还金额'.$amount.'元，最后还款日'.$payday.'【找钱花】';
        //echo $content."\n";
        $content = '{"name":"'.$name.'","amount":"'.$amount.'","day":"'.$payday.'","mobile":"'.$phone.'"}';
        $smstype = '399085';
        if($day==11) {
            $content = '{"name":"'.$name.'","amount":"'.$amount.'"}';
            $smstype = '399084';
        }
        if($day==20) {
            $content = '{"name":"'.$name.'","amount":"'.$amount.'","days":"'.$days.'","overdue_amount":"'.$overdue_amount.'"}';
            $smstype = '399083';
        }
        if($day==100) {
            $content = '{"amount":"'.$amount.'","date":"'.$payday.'"}';
            $smstype = '399082';
        }
        if($day==200) {
            $content = '{"amount":"'.$amount.'","bank":"'.$payday.'"}';
            $smstype = '399081';
        }
        $ret = self::send($mobile, $content, $smstype);
        //阿里不能发催收短信
        //$data = array('name'=>$name,'amount'=>$amount,'day'=>$day);
        //$ret = self::alisend($mobile, 'smsReminder', $data);
        return $ret;
    }

    public static function alisend($mobile, $type, $data=[]) {

        if (empty($mobile) OR empty($type))
        {
            return false;
        }

        $sign = '找钱花';
        //sitename = '';
        switch($type) {
            case 'register':
                $tpl = 'SMS_60200199';
                $code = $data['verifyCode'];
                $SmsParam = "{\"code\":\"$code\"}";
                break;
            case 'reviewedUnPass':
                $tpl = 'SMS_13211153';
                $SmsParam = '';
                break;
            case 'reviewedPass':
                $tpl = 'SMS_13191025';
                $SmsParam = '';
                break;
            case 'orderRepay':
                $tpl = 'SMS_13181454';
                $phone = $data['phone'];
                $name = $data['name'];
                $SmsParam = "{\"phone\":\"$phone\",\"name\":\"$name\"}";
                break;
            case 'smsReminder':
                $tpl = 'SMS_13975050';
                $name = $data['name'];
                $amount = $data['amount'];
                $day = $data['day'];
                $SmsParam = "{\"name\":\"$name\",\"amount\":\"$amount\",\"day\":\"$day\"}";
                break;
            case 'waitReviewed':
                $tpl = 'SMS_13241001';
                $SmsParam = '';
                break;
        }
        //$SmsParam = str_replace(array('{code}'), array($code), $SmsParam);

        //include('/data/webroot/api.9maibei.com/MaiBei/Common/Library/AliSdk/TopSdk.php');
        //include('/home/wwwroot/api.huoyanzichan.com/MaiBei/Common/Library/AliSdk/TopSdk.php');
        date_default_timezone_set('Asia/Shanghai');
        $c = new \TopClient;
        
        $c->appkey = '23732673'; //阿里APP证书AppKey
        $c->secretKey = '95def74672e4b3b4cff62b0b82aed32b'; //阿里APP证书AppSecret
        $r = new \AlibabaAliqinFcSmsNumSendRequest;
        $r->setSmsType('normal');
        $r->setSmsFreeSignName($sign);
        if($SmsParam<>'') { $r->setSmsParam($SmsParam);}
        $r->setRecNum($mobile);
        $r->setSmsTemplateCode($tpl);
        $e = $c->execute($r);

        if($e->result->success) {
            //return json_encode(array('mobile' => $mobile, 'add_time' => time()));
            return true;
        } else {
            return false;
        }
    }

    /**
     * 创世华信短信发送
     * @param $mobile
     * @param $content
     * @return bool
     */
    public static function yunfeng_send_json($mobile, $content){
        Log::sms_write("【*****创世华信----短信发送手机号:".$mobile."---|---发送内容：".$content.'***】');
        $redis = new Redis();
        $key = '控制用户发送短信次数'.$mobile;
        $num = $redis->get($key);
        $ret = '';
        if ($num<11){
            Log::sms_write("【*****创世华信----短信发送手机号:".$mobile."---|---用户短信次数:".$num."***】");
            $retJson = self::huaxinSend($mobile, $content);
            Log::sms_write("【*****创世华信--------短信发送手机号:".$mobile."---|---短信返回结果是：".$retJson."***】");
            $ret = json_decode($retJson, true);
        } else {
            Log::sms_write("【*****创世华信--------短信发送手机号:".$mobile."---|---短信发送失败，原因:大于每日短信次数***】");
            BusinessException::throwException('发送失败');
        }

        if($ret['returnstatus']=='Success'){
            $key = 'contr_sms_send_times_'.$mobile;
            if ($redis->get($key)){
                $redis->set($key,($redis->get($key)+1),21600);
                $a = $redis->get($key);
                Log::sms_write("【*****创世华信--------短信发送手机号:".$mobile."---|---用户短信次数:  ".$a);
            } else {
                $redis->set($key,1,21600);
                Log::sms_write("【*****创世华信--------短信发送手机号:".$mobile."---|---用户短信次数:  1");
            }
            return true;
        }else{
            return false;
        }
    }
    /**
     * description 创世华信短信发送
     * @param $mobile  string 电话
     * @param $content  string 短信内容  【找钱花】尊敬的用户，找钱花本次验证码为123456，请勿泄露
     * @return bool|string
     */
    public static function huaxinSend($mobile, $content)
    {
        $url = self::HUAXIN_URL;
        $account = self::HUAXIN_USER_NAME;
        $key  = self::HUAXIN_KEY;
        $userid = '1111';
        $password = self::getHuaXinPassword($key);
        $gateway = $url."?action=send&userid={$userid}&account={$account}&password={$password}&mobile={$mobile}&content={$content}&sendTime=";
        $result = file_get_contents($gateway);
        return $result;

    }

    /**
     * 密码加密
     * @param $key
     * @return string
     */
    private static function getHuaXinPassword($key)
    {
        $password = strtoupper(md5($key));
        return $password;
    }

    /**
     * 传世华信 余额及已发送量的统计
     * @return bool|string
     */
    public static function huaxinAcount()
    {
        $url = self::HUAXIN_URL;
        $account = self::HUAXIN_USER_NAME;
        $key  = self::HUAXIN_KEY;
        $password = self::getHuaXinPassword($key);
        $userid = '1111';
        $gateway = $url."?action=overage&userid={$userid}&account={$account}&password={$password}";
        $result = file_get_contents($gateway);
        return $result;

    }

    /**
     * description 创世华信状态报告
     * @param string $taskid
     * @return bool|string
     */
    public static function huaxinStatus($taskid='')
    {
        $url = 'http://sh2.ipyy.com/statusJsonApi.aspx';
        $account = self::HUAXIN_USER_NAME;
        $key  = self::HUAXIN_KEY;
        $password = self::getHuaXinPassword($key);
        $userid = '1111';
        $gateway = $url."?action=query&userid={$userid}&account={$account}&password={$password}&taskid={$taskid}";
        $result = file_get_contents($gateway);
        return $result;

    }
    public static function huaxinUpdateLoad()
    {
        $url = 'http://sh2.ipyy.com/callJsonApi.aspx';
        $account = self::HUAXIN_USER_NAME;
        $key  = self::HUAXIN_KEY;
        $password = self::getHuaXinPassword($key);
        $userid = '1111';
        $gateway = $url."?action=query&userid={$userid}&account={$account}&password={$password}";
        $result = file_get_contents($gateway);
        return $result;

    }
}
